package com.genghis.rapidcrm.util;

/**
 * @author xulixin
 */
public final class RapidStrUtil {

    private RapidStrUtil() {
        // reserved.
    }

    private static boolean inCharArray(char ch, char[] arr) {
        for (char trimChar : arr) {
            if (ch == trimChar) {
                return true;
            }
        }
        return false;
    }

    public static String ltrim(String str, String trimStr) {
        char[] trimChars = trimStr.toCharArray();
        int pos = 0;
        for (int i = 0; i < str.length(); i++) {
            if (inCharArray(str.charAt(i), trimChars)) {
                pos += 1;
            } else {
                break;
            }
        }
        return str.substring(pos);
    }

    public static int substrCount(String target, String substr) {
        int count = 0;
        int length = target.length() - substr.length();
        for (int i = 0; i < length; i++) {
            String sourceBak = target.substring(i, i + substr.length());
            int index = sourceBak.indexOf(substr);
            if (index != -1) {
                count++;
            }
        }
        return count;
    }
}
